<{extend name="public/layout"}>


<{block name="content"}>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>会员管理</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="<{:url('/admin/index/index')}>">首页</a></li>
                        <li class="breadcrumb-item"><a href="#">会员管理</a></li>
                        <li class="breadcrumb-item active">会员列表</li>
                    </ol>
                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">


            <div class="card">
                <div class="card-header">
                    <form action="<{:url()}>">
                        <div class="form-row ">

                            <div class="col-auto">
                                <select name="status" class="form-control " >
                                    <option  value="">全部状态</option>
                                    <option <{if null !== $Request.param.status &&$Request.param.status=='1'}>selected<{/if}>  value="1">已禁用</option>
                                    <option <{if null !== $Request.param.status &&$Request.param.status=='0'}>selected<{/if}> value="0">正常</option>

                                </select>
                            </div>

                            <div class="col-auto">

                                <input name="keyword" type="text" class="form-control " placeholder="UID或者账号" value="">
                            </div>

                            <div class="col-auto">
                                <button type="submit" class="btn btn-primary mb-2 "><i class="fas fa-search"></i></button>
                                <a  href="<{:url('index')}>"  class="btn btn-default mb-2 bs-left-30" title="重置"><i class="fas fa-history"></i></a>

                            </div>
                        </div>
                    </form>
                </div>
                <!-- /.card-header -->
                <div class="card-body">
                    <table id="my_table" class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>#</th>
                            <th>账号</th>
                            <th>头像/昵称</th>
                            <th>uid</th>
                            <th>账户</th>
                            <th>登录次数</th>
                            <th>状态</th>
                            <th>备注</th>
                            <th>时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <{if !empty($data)}>
                        <{foreach $data as $item}>
                        <tr>
                            <td><{$item.id}></td>
                            <td>
                                <{$item.account}>
                            </td>
                            <td>
                                <img src="<{$item.avatar}>" style="width: 50px;height: 50px" alt=""> <br>
                                <{$item.nickname}>
                            </td>
                            <td>
                                <{$item.uid}>
                            </td>
                            <td>
                                余额：<a href="<{:url('/admin/caiwu.index/credit',['keyword'=>$item.uid])}>"><{:isset($item.balance)?$item.balance.credit:'0.00'}></a> <br>
                                积分：<{:isset($item.balance)?$item.balance.point:'0.00'}>
                            </td>

                            <td><a title="查看登录记录" href="<{:url('login_log',['keyword'=>$item.uid])}>"><{$item.loginCount}></a></td>


                            <td><{$item.statusDesc}></td>
                            <td class="remark<{$item.uid}>"><{$item.remark}></td>

                            <td>
                                添加：<{$item.add_time}> <br>
                                更新：<{$item.up_time}>
                            </td>
                            <td>

                                <a class="btn  btn-outline-dark btn-xs" title="编辑" href="<{:url('form',['uid'=>$item.uid])}>" >编辑</a>

                                <span class="btn  btn-success btn-xs add-remark" data-uid="<{$item.uid}>"  data-toggle="modal" data-target="#modal-default">备注</span>
                                <{if $item.status=='0'}>
                                <span class="btn  btn-danger btn-xs set-black" data-uid="<{$item.uid}>"  title="封号后不可登录">封号</span>
                                <{else}>
                                <span class="btn  btn-default btn-xs set-black" data-uid="<{$item.uid}>"   title="解封后可以正常操作">解封</span>
                                <{/if}>

                                <span class="btn  btn-outline-primary btn-xs set-recharge" data-credit="<{:isset($item.balance)?$item.balance.credit:'0.00'}>" data-uid="<{$item.uid}>"  data-toggle="modal" data-target="#modal-recharge" title="余额充值">充值</span>
                            </td>

                        </tr>
                        <{/foreach}>
                        <{/if}>



                        </tbody>
                        <tfoot>


                        </tfoot>
                    </table>
                </div>
                <div class="card-footer">
                    <{$page?$page->render():''}>
                </div>
                <!-- /.card-body -->
            </div>
        </div>

        <div class="bs-model">
            <div class="modal fade" id="modal-default">
                <div class="modal-dialog">
                    <form action="<{:url('action_remark')}>" method="post" id="check-form">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4 class="modal-title"></h4>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                            <div class="modal-body">
                                <div class="form-group">
                                    <label for="remark">备注内容</label>
                                    <textarea name="remark" class="form-control" id="remark" placeholder="请填写用户备注"></textarea>
                                    <input type="hidden" name="uid" value="">
                                </div>
                            </div>
                            <div class="modal-footer justify-content-between">
                                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                <button type="button" onclick="sub()" class="btn btn-primary">保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

            <div class="modal fade" id="modal-recharge">
                <div class="modal-dialog">
                    <form action="<{:url('action_recharge')}>" method="post" id="recharge">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4 class="modal-title"></h4>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                            <div class="modal-body">
                                <div class="form-group">
                                    <label for="remark">充值数量</label>
                                    <input type="number" name="credit_num" class="form-control" placeholder="请输入需要充值数量">
                                    <span class="bs-red">当前剩余：<span class="now-credit">0.00</span> </span>
                                    <input type="hidden" class="recharge-uid" name="uid" value="">
                                </div>
                                <div class="form-group">
                                    <label for="r-remark">备注内容</label>
                                    <textarea name="remark" class="form-control" id="r-remark" placeholder="请填写备注"></textarea>
                                </div>
                            </div>
                            <div class="modal-footer justify-content-between">
                                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                <button type="button" onclick="recharge()" class="btn btn-primary">保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>


    </section>
    <!-- /.content -->
</div>
<{/block}>


<{block name="script"}>
<script>
    function sub(){
        form_submit([],'',false,function(res) {
            var uid = $("input[name='uid']").val();
            if (res.code==0){
                $(".remark"+uid).text($("textarea[name='remark']").val())
                $('#modal-default').modal('hide');
                //location.reload();
            }
        })
    }

    function recharge(){
        form_submit([],'',false,function(res) {
            var uid = $("input[name='uid']").val();
            if (res.code==0){
                $('#modal-recharge').modal('hide');
                location.reload();
            }
        },'recharge')
    }
    $(function () {
        $(".set-black").on('click',function () {
            var uid = $(this).data('uid');
            layer.confirm('确定要修改状态吗',{title:'设置状态确认',btn:['确定','再想想']},function (index) {
                sendData("<{:url('/admin/user.index/action_status')}>",{uid:uid},function (res) {
                    if (res.code==0){
                        location.reload()
                        layer.close(index)
                    }
                })

            })
        });
        $(".add-remark").on('click',function () {
            var uid = $(this).data('uid');
            $("textarea[name='remark']").val($(".remark"+uid).text());
            $("input[name='uid']").val(uid);
        });
        $(".set-recharge").on('click',function () {
            var uid = $(this).data('uid');
            var credit = $(this).data('credit');
            $(".now-credit").text(credit);
            $(".recharge-uid").val(uid);
            $("input[name='credit_num']").val(0);
        });


    });

    $(function () {
        $("#my_table").DataTable({
            "ordering": false,//禁用排序
            "responsive": true,
            "lengthChange": false,
            "autoWidth": false,
            //"buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"],
            // "pageLength": 10,         //初始化显示几条数据
            //serverSide: true, // use local process instead of server
            // bFilter: true, // show top right search input box.
            bPaginate: false,//是否开启分页
            //iDisplayLength: 10, //默认显示的记录数
            bInfo: false,//是否显示页脚信息，DataTables插件左下角显示记录数
        }).buttons().container().appendTo('#my_table_wrapper .col-md-6:eq(0)');

    });
</script>
<{/block}>
